package com.audamob.audasingers.tool.adapter;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Typeface;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.LiL.Wayne.Activity.R;
import com.LiL.Wayne.Activity.activity.MusicPlayer;
import com.audamob.audasingers.model.Music;
import com.audamob.audasingers.tool.view.ImageResizerUtils;

public class MusicAdapter extends BaseAdapter {
	private LayoutInflater mInflater;
	private ArrayList<Music> musicList;
	private Activity activity;
	private Typeface font;
	class ViewHolderImage {
		ImageView Logo;
		TextView Name;

		int id;
	}

	public MusicAdapter(Activity activity, ArrayList<Music> list) {
		this.activity = activity;
		this.musicList = list;
		font =Typeface.createFromAsset(this.activity.getAssets(), "ExoMedium.otf");

		mInflater = (LayoutInflater) this.activity
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

	}

	public int getCount() {
		return musicList.size();
	}

	public Object getItem(int position) {
		return position;
	}

	public long getItemId(int position) {
		return position;
	}

	public View getView(final int position, View convertView, ViewGroup parent) {
		final ViewHolderImage holder;
		if (convertView == null) {
			holder = new ViewHolderImage();

			convertView = mInflater.inflate(R.layout.auda_item_music, null);

		
			
			holder.Logo = (ImageView) convertView.findViewById(R.id.Icon);
			holder.Name = (TextView) convertView.findViewById(R.id.nam);

			convertView.setTag(holder);
		} else {
			holder = (ViewHolderImage) convertView.getTag();
		}

		holder.Logo.setId(position);
		holder.Name.setId(position);

		convertView.findViewById(R.id.ItemSong).setOnClickListener(
				new OnClickListener() {

					@Override
					public void onClick(View v) {
						// TODO Auto-generated method stub
						// TODO Auto-generated method stub
						Intent i = new Intent(activity.getBaseContext(),
								MusicPlayer.class);
						i.putExtra("name", musicList.get(position).getName());
						i.putExtra("album", musicList.get(position).getUrl());
						i.putExtra("feat", musicList.get(position)
								.getFeatring());
						i.putExtra("mode", 1);
						activity.startActivity(i);

						activity.overridePendingTransition(R.anim.push_down_in,
								R.anim.push_down_out);
					}
				});

		holder.Name.setTypeface(font);
		holder.Name.setText(musicList.get(position).getName());
		holder.id = position;

		return convertView;
	}
}
